package com.example.lenovo.test02;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_main);
        //绑定初始化ButterKnife
        ButterKnife.bind(this);

        textView = findViewById(R.id.text);

        //Activity
        Button btn01 = findViewById(R.id.btn1);
        btn01.setOnClickListener((View.OnClickListener) this);

        //匿名内部类
        Button btn02 = findViewById(R.id.btn2);
        btn02.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textView.setText("使用匿名内部类作为监听器");
            }
        });

        //内部类
        Button btn04 = findViewById(R.id.btn4);
        MyButton listener = new MyButton();
        btn04.setOnClickListener(listener);

        //外部类
        Button btn05 = findViewById(R.id.btn5);
        btn05.setOnClickListener(new MyButtonListener());

        //跳转到系统信息
        Button btn_SM=findViewById(R.id.btn_SystemMessage);
        btn_SM.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,ConfigurationTest.class);
                startActivity(intent);
            }
        });

        //跳转到模拟进度条
        Button btn_PB=findViewById(R.id.btn_ProgressBar);
        btn_PB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,ProgressDialogTest.class);
                startActivity(intent);
            }
        });

    }

    //Activity
    public void onClick(View v) {
        textView.setText("事件本身作为监听器");
    }

    //ButterKnife绑定
    @OnClick(R.id.btn6)
    public void ButterClick(){
        textView.setText("使用黄油刀实现监听");
    }

    //绑定到标签
    public void onClick03(View v) {
        textView.setText("使用绑定到标签方式实现监听");
    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
        textView.setText("事件本身作为监听器");
    }

    class MyButton implements View.OnClickListener {
        public void onClick(View v) {
            textView.setText("使用内部类作为监听器");
        }
    }

    class MyButtonListener implements View.OnClickListener {
        public MyButtonListener() {
            super();
        }

        public void onClick(View v) {
            textView.setText("使用外部类作为监听器");
        }
    }

}
